home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / smtp / main.frm (.txt) next >
Encoding:
Visual Basic Form  |  1998-03-28  |  8.4 KB  |  240 lines

  1. VERSION 5.00
  2. Object = "{248DD890-BB45-11CF-9ABC-0080C7E7B78D}#1.0#0"; "MSWINSCK.OCX"
  3. Begin VB.Form frmMain 
  4.    Caption         =   "SMTP E-Mail Tester"
  5.    ClientHeight    =   4845
  6.    ClientLeft      =   60
  7.    ClientTop       =   345
  8.    ClientWidth     =   7185
  9.    Icon            =   "Main.frx":0000
  10.    LinkTopic       =   "Form1"
  11.    MaxButton       =   0   'False
  12.    ScaleHeight     =   4845
  13.    ScaleWidth      =   7185
  14.    StartUpPosition =   2  'CenterScreen
  15.    Begin VB.Frame Frame1 
  16.       Caption         =   "Status:"
  17.       Height          =   615
  18.       Left            =   960
  19.       TabIndex        =   15
  20.       Top             =   3480
  21.       Width           =   5175
  22.       Begin VB.Label StatusTxt 
  23.          Height          =   255
  24.          Left            =   120
  25.          TabIndex        =   16
  26.          Top             =   240
  27.          Width           =   4935
  28.       End
  29.    End
  30.    Begin VB.TextBox txtEmailServer 
  31.       Height          =   285
  32.       Left            =   3600
  33.       TabIndex        =   13
  34.       Top             =   1440
  35.       Width           =   3375
  36.    End
  37.    Begin VB.TextBox ToNametxt 
  38.       Height          =   285
  39.       Left            =   3600
  40.       TabIndex        =   11
  41.       Top             =   840
  42.       Width           =   3375
  43.    End
  44.    Begin VB.TextBox txtFromName 
  45.       Height          =   285
  46.       Left            =   3600
  47.       TabIndex        =   9
  48.       Top             =   240
  49.       Width           =   3375
  50.    End
  51.    Begin VB.CommandButton Command2 
  52.       Caption         =   "&Exit"
  53.       Height          =   495
  54.       Left            =   4440
  55.       TabIndex        =   8
  56.       Top             =   4200
  57.       Width           =   1695
  58.    End
  59.    Begin VB.TextBox txtEmailBodyOfMessage 
  60.       Height          =   1455
  61.       Left            =   120
  62.       MultiLine       =   -1  'True
  63.       ScrollBars      =   2  'Vertical
  64.       TabIndex        =   7
  65.       Top             =   1920
  66.       Width           =   6855
  67.    End
  68.    Begin VB.TextBox txtEmailSubject 
  69.       Height          =   285
  70.       Left            =   120
  71.       TabIndex        =   5
  72.       Top             =   1440
  73.       Width           =   3255
  74.    End
  75.    Begin VB.TextBox txtToEmailAddress 
  76.       Height          =   285
  77.       Left            =   120
  78.       TabIndex        =   3
  79.       Top             =   840
  80.       Width           =   3255
  81.    End
  82.    Begin VB.TextBox txtFromEmailAddress 
  83.       Height          =   285
  84.       Left            =   120
  85.       TabIndex        =   1
  86.       Top             =   240
  87.       Width           =   3255
  88.    End
  89.    Begin VB.CommandButton Command1 
  90.       Caption         =   "&Send E-Mail"
  91.       Height          =   495
  92.       Left            =   960
  93.       TabIndex        =   0
  94.       Top             =   4200
  95.       Width           =   2175
  96.    End
  97.    Begin MSWinsockLib.Winsock Winsock1 
  98.       Left            =   3480
  99.       Top             =   4200
  100.       _ExtentX        =   741
  101.       _ExtentY        =   741
  102.       _Version        =   327681
  103.    End
  104.    Begin VB.Label Label6 
  105.       Caption         =   "E-Mail Server"
  106.       Height          =   255
  107.       Left            =   3600
  108.       TabIndex        =   14
  109.       Top             =   1200
  110.       Width           =   3375
  111.    End
  112.    Begin VB.Label Label5 
  113.       Caption         =   "There Name"
  114.       Height          =   255
  115.       Left            =   3600
  116.       TabIndex        =   12
  117.       Top             =   600
  118.       Width           =   3375
  119.    End
  120.    Begin VB.Label Label4 
  121.       Caption         =   "Your Name"
  122.       Height          =   255
  123.       Left            =   3600
  124.       TabIndex        =   10
  125.       Top             =   0
  126.       Width           =   3135
  127.    End
  128.    Begin VB.Label Label3 
  129.       Caption         =   "Subject"
  130.       Height          =   255
  131.       Left            =   120
  132.       TabIndex        =   6
  133.       Top             =   1200
  134.       Width           =   1215
  135.    End
  136.    Begin VB.Label Label2 
  137.       Caption         =   "To"
  138.       Height          =   255
  139.       Left            =   120
  140.       TabIndex        =   4
  141.       Top             =   600
  142.       Width           =   1575
  143.    End
  144.    Begin VB.Label Label1 
  145.       Caption         =   "From (e-mail address)"
  146.       Height          =   255
  147.       Left            =   120
  148.       TabIndex        =   2
  149.       Top             =   0
  150.       Width           =   1575
  151.    End
  152. Attribute VB_Name = "frmMain"
  153. Attribute VB_GlobalNameSpace = False
  154. Attribute VB_Creatable = False
  155. Attribute VB_PredeclaredId = True
  156. Attribute VB_Exposed = False
  157. Dim Response As String, Reply As Integer, DateNow As String
  158. Dim first As String, Second As String, Third As String
  159. Dim Fourth As String, Fifth As String, Sixth As String
  160. Dim Seventh As String, Eighth As String
  161. Dim Start As Single, Tmr As Single
  162. Sub SendEmail(MailServerName As String, FromName As String, FromEmailAddress As String, ToName As String, ToEmailAddress As String, EmailSubject As String, EmailBodyOfMessage As String)
  163.           
  164.     Winsock1.LocalPort = 0 ' Must set local port to 0 (Zero) or you can only send 1 e-mail pre program start
  165. If Winsock1.State = sckClosed Then ' Check to see if socet is closed
  166.     DateNow = Format(Date, "Ddd") & ", " & Format(Date, "dd Mmm YYYY") & " " & Format(Time, "hh:mm:ss") & "" & " -0600"
  167.     first = "mail from:" + Chr(32) + FromEmailAddress + vbCrLf ' Get who's sending E-Mail address
  168.     Second = "rcpt to:" + Chr(32) + ToEmailAddress + vbCrLf ' Get who mail is going to
  169.     Third = "Date:" + Chr(32) + DateNow + vbCrLf ' Date when being sent
  170.     Fourth = "From:" + Chr(32) + FromName + vbCrLf ' Who's Sending
  171.     Fifth = "To:" + Chr(32) + ToNametxt + vbCrLf ' Who it going to
  172.     Sixth = "Subject:" + Chr(32) + EmailSubject + vbCrLf ' Subject of E-Mail
  173.     Seventh = EmailBodyOfMessage + vbCrLf ' E-mail message body
  174.     Ninth = "X-Mailer: EBT Reporter v 2.x" + vbCrLf ' What program sent the e-mail, customize this
  175.     Eighth = Fourth + Third + Ninth + Fifth + Sixth  ' Combine for proper SMTP sending
  176.     Winsock1.Protocol = sckTCPProtocol ' Set protocol for sending
  177.     Winsock1.RemoteHost = MailServerName ' Set the server address
  178.     Winsock1.RemotePort = 25 ' Set the SMTP Port
  179.     Winsock1.Connect ' Start connection
  180.     WaitFor ("220")
  181.     StatusTxt.Caption = "Connecting...."
  182.     StatusTxt.Refresh
  183.     Winsock1.SendData ("HELO worldcomputers.com" + vbCrLf)
  184.     WaitFor ("250")
  185.     StatusTxt.Caption = "Connected"
  186.     StatusTxt.Refresh
  187.     Winsock1.SendData (first)
  188.     StatusTxt.Caption = "Sending Message"
  189.     StatusTxt.Refresh
  190.     WaitFor ("250")
  191.     Winsock1.SendData (Second)
  192.     WaitFor ("250")
  193.     Winsock1.SendData ("data" + vbCrLf)
  194.     WaitFor ("354")
  195.     Winsock1.SendData (Eighth + vbCrLf)
  196.     Winsock1.SendData (Seventh + vbCrLf)
  197.     Winsock1.SendData ("." + vbCrLf)
  198.     WaitFor ("250")
  199.     Winsock1.SendData ("quit" + vbCrLf)
  200.     StatusTxt.Caption = "Disconnecting"
  201.     StatusTxt.Refresh
  202.     WaitFor ("221")
  203.     Winsock1.Close
  204.     MsgBox (Str(Winsock1.State))
  205. End If
  206. End Sub
  207. Sub WaitFor(ResponseCode As String)
  208.     Start = Timer ' Time event so won't get stuck in loop
  209.     While Len(Response) = 0
  210.         Tmr = Start - Timer
  211.         DoEvents ' Let System keep checking for incoming response **IMPORTANT**
  212.         If Tmr > 50 Then ' Time in seconds to wait
  213.             MsgBox "SMTP service error, timed out while waiting for response", 64, MsgTitle
  214.             Exit Sub
  215.         End If
  216.     Wend
  217.     While Left(Response, 3) <> ResponseCode
  218.         DoEvents
  219.         If Tmr > 50 Then
  220.             MsgBox "SMTP service error, impromper response code. Code should have been: " + ResponseCode + " Code recieved: " + Response, 64, MsgTitle
  221.             Exit Sub
  222.         End If
  223.     Wend
  224. Response = "" ' Sent response code to blank **IMPORTANT**
  225. End Sub
  226. Private Sub Command1_Click()
  227.     SendEmail txtEmailServer.Text, txtFromName.Text, txtFromEmailAddress.Text, txtToEmailAddress.Text, txtToEmailAddress.Text, txtEmailSubject.Text, txtEmailBodyOfMessage.Text
  228.     'MsgBox ("Mail Sent")
  229.     StatusTxt.Caption = "Mail Sent"
  230.     StatusTxt.Refresh
  231.     Beep
  232.     Close
  233. End Sub
  234. Private Sub Command2_Click()
  235.     End
  236. End Sub
  237. Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
  238.     Winsock1.GetData Response ' Check for incoming response *IMPORTANT*
  239. End Sub
  240.